
package com.tempprojectgroupmodule.dao;
import com.tempprojectgroupmodule.bean.*;
import java.sql.*;
import java.util.*;
import util.*;
public class TbTempProjectGroupDAO {
    private Connection conn = null;
    private PreparedStatement pt = null;
    private ResultSet rs = null;
    private boolean flag = false;
    private String sql = "";
    private TbTempProjectGroup tbTempProjectGroup=null;
    private List<TbTempProjectGroup> tbTempProjectGroupList=null;

    public boolean add(TbTempProjectGroup inTbTempProjectGroup){
        try{
            
        conn=ConnectDB.getSqlServerConnection();
        sql="insert into Tb_TempProjectGroup(TempProjectGroupCode,TempProjectGroupName,TempProjectGroupMaster,TempProjectGroupMembers,TempProjectGroupCreateTime) values(?,?,?,?,?)";
        pt = conn.prepareStatement(sql);
        
        pt.setString(1,inTbTempProjectGroup.getTempProjectGroupCode());
        pt.setString(2, inTbTempProjectGroup.getTempProjectGroupName());
        pt.setString(3,inTbTempProjectGroup.getTempProjectGroupMaster());
        pt.setString(4,inTbTempProjectGroup.getTempProjectGroupMembers());
        pt.setString(5,inTbTempProjectGroup.getTempProjectGroupCreateTime());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
            ConnectDB.closeSqlConnection();
        }
        return flag;
    }
    public boolean del(int inTempProjectGroupId){
        return UtilDAO.del("Tb_TempProjectGroup", "TempProjectGroupId", inTempProjectGroupId);
    }
    public boolean edit(TbTempProjectGroup inTbTempProjectGroup){
        try{
            
        conn=ConnectDB.getSqlServerConnection();
        sql="update Tb_TempProjectGroup set  TempProjectGroupCode=?,TempProjectGroupName=?,TempProjectGroupMaster=?,TempProjectGroupMembers=?,TempProjectGroupCreateTime=? where TempProjectGroupId=?";
        pt = conn.prepareStatement(sql);
        
        pt.setString(1,inTbTempProjectGroup.getTempProjectGroupCode());
        pt.setString(2, inTbTempProjectGroup.getTempProjectGroupName());
        pt.setString(3,inTbTempProjectGroup.getTempProjectGroupMaster());
        pt.setString(4,inTbTempProjectGroup.getTempProjectGroupMembers());
        pt.setString(5,inTbTempProjectGroup.getTempProjectGroupCreateTime());
        pt.setInt(6,inTbTempProjectGroup.getTempProjectGroupId());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
            ConnectDB.closeSqlConnection();
        }
        return flag;
    }
    public TbTempProjectGroup getTbTempProjectGroupByTempProjectGroupId(int inTempProjectGroupId) {
        tbTempProjectGroup=null;
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_TempProjectGroup where TempProjectGroupId=? ";
            pt = conn.prepareStatement(sql);
            pt.setInt(1,inTempProjectGroupId);
            rs = pt.executeQuery();
            while (rs.next()) {
                if (tbTempProjectGroup == null)tbTempProjectGroup = getTbTempProjectGroup(rs);
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
            ConnectDB.closeSqlConnection();
        }
        return tbTempProjectGroup;
    }
    public List<TbTempProjectGroup> getTbTempProjectGroupAll() {
        tbTempProjectGroupList=new ArrayList<TbTempProjectGroup>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_TempProjectGroup";
            pt = conn.prepareStatement(sql);
            rs = pt.executeQuery();
            while (rs.next()) {
                tbTempProjectGroupList.add(getTbTempProjectGroup(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
            ConnectDB.closeSqlConnection();
        }
        return tbTempProjectGroupList;
    }
    public List<TbTempProjectGroup> getTbTempProjectGroupAll(VskPage vp) {
        tbTempProjectGroupList=new ArrayList<TbTempProjectGroup>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_TempProjectGroup";
            vp.setAllCountSql(sql);
            vp.getAllRecordCount(conn, vp.getAllCountSql());
            pt = conn.prepareStatement(vp.processPageSql( "Tb_TempProjectGroup", "TempProjectGroupId"));
            rs = pt.executeQuery();
            while (rs.next()) {
                tbTempProjectGroupList.add(getTbTempProjectGroup(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
            ConnectDB.closeSqlConnection();
        }
        return tbTempProjectGroupList;
    }
    public TbTempProjectGroup getTbTempProjectGroup(ResultSet rs) throws Exception{
        TbTempProjectGroup tbTempProjectGroup = new TbTempProjectGroup();
        tbTempProjectGroup.setTempProjectGroupId(rs.getInt("TempProjectGroupId"));
        tbTempProjectGroup.setTempProjectGroupCode(rs.getString("TempProjectGroupCode"));
        tbTempProjectGroup.setTempProjectGroupName(rs.getString("TempProjectGroupName"));
        tbTempProjectGroup.setTempProjectGroupMaster(rs.getString("TempProjectGroupMaster"));
        tbTempProjectGroup.setTempProjectGroupMembers(rs.getString("TempProjectGroupMembers"));
        tbTempProjectGroup.setTempProjectGroupCreateTime(rs.getString("TempProjectGroupCreateTime"));
        return tbTempProjectGroup;
    }
    public static void main(String[] args) {
		List<TbTempProjectGroup> tList=new TbTempProjectGroupDAO().getTbTempProjectGroupAll();
		for(int i=0;i<tList.size();i++){
			TbTempProjectGroup t=tList.get(i);
			System.out.println(t.getTempProjectGroupName());
		}
	}
}
